 <div class="content_left left">

  <?=Modules::run('category/munu_left',$this->uri->segment(2));?>

  <div class="content_member_right left">
    <div class="form_contact">
      <form action="<?=PATH_URL_LANG.'users/ajax_register'?>" name="register" id='register' method='post'>
        <div class="mt20"><i><strong>Register an account</strong></i></div>

        <div id="error_input" class='mt5' style='display:none; color: red; font-size: 13px;'></div>
        <div id="alert" class='mt5' style='display:none; color: green; font-size: 13px;'><?=lang('register_success')?></div>

        <div class="mt15">
          <div class="lable left"><?=lang('name')?></div>
          <div class="input left"><input type="text" name="co_name" id='co_name' /></div>
          <div class="note left">(*)</div>
          <div class="clearAll"></div>
        </div>
        <div class="mt15">
          <div class="lable left"><?=lang('your_name')?></div>
          <div class="input left"><input type="text" name="co_username" id='co_username' /></div>
          <div class="note left">(*)</div>
          <div class="clearAll"></div>
        </div>
        <div class="mt15">
          <div class="lable left"><?=lang('your_pass')?></div>
          <div class="input left"><input type="password" name="co_password" id='co_password' /></div>
          <div class="note left">(*)</div>
          <div class="clearAll"></div>
        </div>
        <div class="mt15">
          <div class="lable left"><?=lang('password_confirm')?></div>
          <div class="input left"><input type="password" name="co_password_confirm" id='co_password_confirm' /></div>
          <div class="note left">(*)</div>
          <div class="clearAll"></div>
        </div>
        <div class="mt15">
          <div class="lable left"><?=lang('email')?></div>
          <div class="input left"><input type="text" name="co_email" id="co_email" /></div>
          <div class="note left">(*)</div>
          <div class="clearAll"></div>
        </div>
        <div class="mt15">
          <div class="lable left"><?=lang('phone')?></div>
          <div class="input left"><input type="text" name="co_phone" id='co_phone' /></div>
          <div class="note left">(*)</div>
          <div class="clearAll"></div>
        </div>
        <div class="mt15">
          <div class="lable left"><?=lang('address')?></div>
          <div class="input left"><input type="text" name="co_address" id='co_address' /></div>
          <div class="note left">(*)</div>
          <div class="clearAll"></div>
        </div>

        <div class="mt10"><span class="note">(*)</span> <strong><i><?=lang('required')?></i></strong></div>
        <div class="mt8">
          <div class="lable left">&nbsp;</div>
          <div class="input left txt_r">
            <div id='captcha-img'><?=$cap_img;?>&nbsp;<a style="vertical-align:9px;" href="javascript:void(0)"  onclick="reCaptcha()"><img class="png" alt="" src="<?=PATH_URL?>static/images/btn/btn_reset_check.png"></a>&nbsp;<input type="text" name="inp_captcha" id='inp_captcha' class="text_check"></div>
            <div class="mt7"><a href="javascript:void(0)" onclick='return validate_input();'><img src="<?=PATH_URL?>static/images/btn/btn_send.jpg" alt="" /></a></div>
          </div>
        </div>
      </form>
    </div>
    <div style="height:125px;"></div>
  </div><!-- end .content_member -->
  <div class="clearAll"></div>
</div><!-- end .content_left -->

<div class="content_right right">
  <?=Modules::run('users/block','user_info')?>
</div><!-- end .content_right -->

<script>
  function validate_input(){
    if ($('#co_name').val() == '') {
      $('#co_name').focus();
      $('#error_input').html("<?=lang('error_empty')?> !");
      $('#error_input').show();
      //alert("Vui lòng chọn loại sản phẩm!");
      return false;
    }

    if ($('#co_username').val() == '') {
      $('#co_username').focus();
      $('#error_input').html("<?=lang('error_empty')?> !");
      $('#error_input').show();
      //alert("Vui lòng chọn loại sản phẩm!");
      return false;
    }

    if ($('#co_password').val() == '') {
      $('#co_password').focus();
      $('#error_input').html("<?=lang('error_empty')?> !");
      $('#error_input').show();
      return false;
    }

    if ($('#co_password_confirm').val() =='') {
      $('#co_password_confirm').focus();
      $('#error_input').html("<?=lang('error_empty')?> !");
      $('#error_input').show();
      return false;
    }else if( $('#co_password_confirm').val() != $('#co_password').val()) {
      $('#co_password_confirm').focus();
      $('#error_input').show();
      $('#error_input').html("<?=lang('password_cofirm_error')?>");
      $('#email').focus();
      return false;
    }

    var filter = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
    if ($('#co_email').val() == '') {
      $('#co_email').focus();
      $('#error_input').html("<?=lang('error_empty')?> !");
      $('#error_input').show();
      return false;
    }else if(!filter.test($('#co_email').val())) {
      $('#error_input').show();
      $('#error_input').html("<?=lang('error_incorrect_email')?> !");
      $('#email').focus();
      return false;
    }

    if ($('#co_phone').val() == '') {
      $('#co_phone').focus();
      $('#error_input').html("<?=lang('error_empty')?> !");
      $('#error_input').show();
      return false;
    }
    else if (!isPhone($('#co_phone').val())) {
        $('#co_phone').focus();
        $('#error_input').show();
        $('#error_input').html("<?=lang('error_incorrect_phone')?> !");
        return false;
    }

    if ($('#co_address').val() == '') {
      $('#co_address').focus();
      $('#error_input').html("<?=lang('error_empty')?> !");
      $('#error_input').show();
      return false;
    }

    if ($('#inp_captcha').val() == '') {
      $('#inp_captcha').focus();
      $('#error_input').html("<?=lang('error_empty')?> !");
      $('#error_input').show();
      return false;
    }

    //send contact
    data = $('#register').serialize();
    url = $('#register').attr('action');
    $.post(url, data, function(response){
      if(response == 'incorrect_captcha'){
        $('#error_input').html("<?=lang('error_captcha')?>");
        $('#inp_captcha').focus();
        $('#error_input').show();
      }
      else if(response == 'error-username-exists'){
        $('#error_input').html("<?=lang('username_exist')?>");
        $('#inp_captcha').focus();
        $('#error_input').show();
      }
      else if(response == 'error-email-exists'){
        $('#error_input').html("<?=lang('email_exist')?>");
        $('#inp_captcha').focus();
        $('#error_input').show();
      }
      else if(response == '1'){
        //success
        $('#error_input').hide();
        show_alert_success();
        //reset form input
        reset_form();
      }
      else{
        $('#error_input').html("<?=lang('error_input')?>");
        $('#error_input').show();
      }

    });

    return false;
  }

  function isPhone(s){

    var isMatch = /^(9[0-9]{9}|1[0-9]{10}|09[0-9]{8}|01[0-9]{9}|[0-9]{9,13})$/.test(s);
    if(isMatch){
      isMatch = s.length == 10 && s.indexOf("09") == 0;
      if(isMatch){
        return true;
      }
      else{
        isMatch = s.length == 11 && s.indexOf("01") == 0;
        if(isMatch){
          return true;
        }
        else{
          return false;
        }
      }
    }
    else{
      return false;
    }
  }

  function check_email(){
    var filter = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
    if ($('#co_email').val() == '') {
      $('#co_email').focus();
      $('#error_input').html("<?=lang('error_empty')?> !");
      $('#error_input').show();
      return false;
    }else if(!filter.test($('#email').val())) {
      $('#error_input').show();
      $('#error_input').html("<?=lang('error_incorrect_email')?> !");
      $('#email').focus();
      return false;
    }
    return true;
  }

  function check_email_confirm(){
    var filter = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
    if ($('#co_email_confirm').val() =='') {
      $('#co_email_confirm').focus();
      $('#error_input').html("<?=lang('error_empty')?> !");
      $('#error_input').show();
      return false;
    }else if( $('#co_email').val() != $('#co_email_confirm').val()) {
      $('#error_input').show();
      $('#error_input').html("These email don't match !");
      $('#email').focus();
      return false;
    }
    return true;
  }

  function reset_form(){
    $('#register input,#register textarea').val('');

  }

  function show_alert_error(){
    $("#error_input").fadeIn(500);
    setTimeout("$('#error_input').fadeOut(300); ",5000)
  }

  function show_alert_success(){
    $("#alert").fadeIn(500);
    setTimeout("$('#alert').fadeOut(300); ",10000)
  }
</script>
